<?php
include("db.inc");

if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
	{
		if ($_FILES["file"]["error"] > 0)
	    {
			//echo "Error: " . $_FILES["file"]["error"] . "<br />";
			header('Location: index.php?page=profile.php');
	    }
		else
		{
			if (!file_exists("user_pick/".$_SESSION['User']['id'])) {
				mkdir("user_pick/".$_SESSION['User']['id'], 0777, TRUE);
				move_uploaded_file($_FILES["file"]["tmp_name"],  "user_pick/".$_SESSION['User']['id']."/avatar.jpeg");
			}
			$persona = $_POST['persona'];
			$style = $_POST['style'];
			$brands = $_POST['brands'];
			
			mysql_query("UPDATE users SET description='".$persona."', style_id=".$style." WHERE id=1");
			$total_brands = count($brands);
			for($i=0; $i < $total_brands; $i++){
				mysql_query("INSERT INTO users_brands (user_id, brand_id) VALUES ('".$_SESSION['User']['id']."','".$brands[$i]."')");
			}
			header('Location: index.php?page=advice.php');
		}
	}
	else
	{
		header('Location: index.php?page=profile.php');
	}
?>